<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<meta charset="utf-8">
<head>
    <link type="text/css" href="${pageContext.request.contextPath}/css/booksDetailsUpdate.css" rel="stylesheet">
   <title>更改图书信息</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/scripts/jquery-3.2.1.js"></script>
    <script type="application/javascript">


        $(function () {
            $.ajax({
                type:"post",
                url:"/login/titleServlet",
                dataType:"json",
                data:{
                    "doType":"doQuery"
                },
                success:function (data) {
                    var temp="<select name=\"class\">\n" +
                        "                <option>选择图书分类-------</option>"
                    for (var i=0;i<data.length;i++){
                        temp+="<option value='"+data[i].id+"'>"+data[i].title+"</option>"
                    }
                    temp+="</select>"
                    $("[id=class]").html(temp);
                }
            })

            $("[name=book]").blur(function () {
                var book=$(this).val();
                $("[name=bookName]").html(book)
            })
            //提交图书信息
            $("[value=提交修改后的图书信息]").click(function () {
                var book=$("[name=book]").val()
                var writer=$("[name=writer]").val()
                var press=$("[name=press]").val()
                var publicationTime=$("[name=publicationTime]").val()

                var titleTwoId=$("[name=class]").val()
                var printingTime=$("[name=printingTime]").val()
                var print=$("[name=print]").val()
                var ISBN=$("[name=ISBN]").val()

                var pricing=$("[name=pricing]").val()
                var price=$("[name=price]").val()
                var repertory=$("[name=repertory]").val()
                var words=$("[name=words]").val()
                var pages=$("[name=pages]").val()
                var format=$("[name=format]").val()
                var sheet=$("[name=sheet]").val()
                var pack=$("[name=pack]").val()
                var contentIntro=$("[name=contentIntro]").val()
                var writerIntro=$("[name=writerIntro]").val()
                var catalogue=$("[name=catalogue]").val()
                var mediaComments=$("[name=mediaComments]").val()
                var excerpt=$("[name=excerpt]").val()
                var intro=$("[name=intro]").val()
                var bookId=$("[name=bookId]").val()
                $.ajax({
                    type:"post",
                    url:"/login/booksDetailsServlet",
                    data:{
                        "doType":"doUpdate",
                        "book":book,
                        "writer":writer,
                        "press":press,
                        "publicationTime":publicationTime,
                        "titleTwoId":titleTwoId,
                        "printingTime":printingTime,
                        "print":print,
                        "ISBN":ISBN,
                        "pricing":pricing,
                        "price":price,
                        "repertory":repertory,
                        "words":words,
                        "pages":pages,
                        "format":format,
                        "sheet":sheet,
                        "pack":pack,
                        "contentIntro":contentIntro,
                        "writerIntro":writerIntro,
                        "catalogue":catalogue,
                        "mediaComments":mediaComments,
                        "excerpt":excerpt,
                        "intro":intro,
                        "bookId":bookId
                    },
                    success:function (data) {
                        if(data==0) {
                            alert("更改失败！")
                        }else {
                            alert("更改成功！")
                        }
                    }
                })
            })
        })
    </script>
</head>
<body >
    <div id="container" align="center">
        <!--页面头部栏-->
        <div id="head">
            <iframe src="${pageContext.request.contextPath}/head.jsp"width="100%"height="100%"scrolling="no"frameborder="0">
            </iframe>
        </div>

        <!--页面购物车栏-->
        <div id="center">
            <c:forEach items="${bookDetails}" var="book">
                <input type="hidden" name="bookId" value="${book.bookId}">
                <div id="book">
                    <div id="bookName">
                        <h3><span name="bookName">${book.book}</span></h3>
                        丛书名：<span name="bookName">${book.book}</span>
                    </div>
                    <div id="message">
                        <img src="${pageContext.request.contextPath}/${book.cover}" id="imgId">
                        <%--<div id="upload">
                            <form method="post"  enctype="multipart/form-data" id="uploadForm">
                                <input id="fileId" type="file" name="uploadFile" onchange="preview(this)" >
                                <input type="button" value="上传图书封面" >
                            </form>
                        </div>--%>
                        <ul id="ul1">
                            <li>书名:</li>
                            <li>作者:</li>
                            <li>出版社:</li>
                            <li>出版时间:</li>
                            <li>图书分类:</li>
                            <li>印刷时间:</li>
                            <li>印次:</li>
                            <li>ISBN:</li>
                        </ul>
                        <ul id="ul1-1">
                            <li><input name="book" value="${book.book}"></li>
                            <li><input name="writer" value="${book.writer}"></li>
                            <li><input name="press" value="${book.press}"></li>
                            <li><input name="publicationTime" value="${book.publicationTime}"></li>
                            <li id="class">

                            </li>
                            <li><input name="printingTime" value="${book.printingTime}"></li>
                            <li><input name="print" value="${book.print}"></li>
                            <li><input name="ISBN" value="${book.ISBN}"></li>
                        </ul>
                        <ul id="ul2">
                            <li>定价:</li>
                            <li>当当价:</li>
                            <li>库存:</li>
                            <li>字数:</li>
                            <li>页数</li>
                            <li>开本:</li>
                            <li>纸张:</li>
                            <li>包装:</li>
                        </ul>
                        <ul id="ul2-1">
                            <li><input name="pricing" value="${book.pricing}"></li>
                            <li><input name="price" value="${book.price}"></li>
                            <li><input name="repertory" value="${book.repertory}"></li>
                            <li><input name="words" value="${book.words}"></li>
                            <li><input name="pages" value="${book.pages}"></li>
                            <li><input name="format" value="${book.format}"></li>
                            <li><input name="sheet" value="${book.sheet}"></li>
                            <li><input name="pack" value="${book.pack}"></li>
                        </ul>


                    </div>

                    <div id="contentDetails">
                        <div id="intro">
                            <h3>图书简介</h3>
                            <textarea name="intro" cols="105" rows="2">${book.intro}</textarea>
                        </div>
                        <div id="contentSynopsis">
                            <h3>内容简介</h3>
                            <textarea name="contentIntro" cols="105" rows="5">${book.contentIntro}</textarea>
                        </div>

                        <div id="writerSynopsis">
                            <h3>作者简介</h3>
                            <textarea name="writerIntro" cols="105" rows="5">${book.writerIntro}</textarea>
                        </div>

                        <div id="catalogue">
                            <h3>目录</h3>
                            <textarea name="catalogue" cols="105" rows="5">${book.catalog}</textarea>
                        </div>

                        <div id="comment ">
                            <h3>媒体评论</h3>
                            <div id="mediaComments"><textarea name="mediaComments" cols="105" rows="5">${book.mediaComments}</textarea></div>
                        </div>

                        <div id="digest ">
                            <h3>书摘插图</h3>
                            <textarea name="excerpt" cols="105" rows="5">${book.excerpt}</textarea>
                        </div>
                        <input type="button" value="提交修改后的图书信息" id="input">
                    </div>
                </div>
            </c:forEach>
        </div>

        <!--页面脚注栏-->
        <div id="foot">
            <iframe src="${pageContext.request.contextPath}/foot.jsp"width="100%"height="100%"scrolling="no"frameborder="0">
            </iframe>
        </div>
    </div>
</body>
</html>
